package com.pmstation.skin

import java.awt.Color
import math._
import collection.mutable.ListBuffer

/**
 * Created by IntelliJ IDEA.
 * User: denny
 * Date: Jul 15, 2010
 * Time: 4:01:12 PM
 * To change this template use File | Settings | File Templates.
 */

class ColorDiffCos{
  def diffCos(rgb1:Int, rgb2:Int) = {
    val c1 = new Color(rgb1)
    val c2 = new Color(rgb2)

    1 - (c1.getRed*c2.getRed + c1.getGreen*c2.getGreen + c1.getBlue*c2.getBlue) / vectorLen(c1) / vectorLen(c2)
  }

  def vectorLen(c:Color) = sqrt(c.getRed*c.getRed + c.getGreen*c.getGreen + c.getBlue*c.getBlue)

  val buf = new ListBuffer[Int]
  var max:Double=0

  def update(rgb: Int){
    for( i <- buf ){
      max = max.max( diffCos(i, rgb) )
    }
    buf += rgb
  }

  def maxDiff = max

}